import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
import { ITypeData } from './dict.type'
enum Api {
	list = 'key-values/Trees/',
	alllist = 'key-values/Trees/',
	addType = 'key-values',
	typelist = 'key-values/Value/'
}

export const list = (parentId: number | string) => defHttp.get({ url: Api.list + parentId });
export const allList = (parentId: number | string) => defHttp.get({ url: Api.alllist + parentId });
export const Type = {
	add: (data: ITypeData) => defHttp.post({ url: Api.addType, data }),
	edit: (data: ITypeData) => defHttp.put({ url: `${Api.addType}/${data.id}`, data })
}
export const typeInfo = (code: number | string) => defHttp.get({ url: Api.addType + '/' + code });
export const delInfo = (id: number | string) => defHttp.delete({ url: Api.addType + '/' + id });
export const listTypeApi = (parentId: string) => defHttp.get({ url: Api.typelist + parentId });

export const batchDeleteDict = (params, handleSuccess) => {
	Modal.confirm({
		title: '确认删除',
		content: '是否删除选中数据',
		okText: '确认',
		cancelText: '取消',
		onOk: () => {
			return defHttp.delete({ url: Api.list, data: params }, { joinParamsToUrl: true }).then(() => {
				handleSuccess();
			});
		},
	});
};